/***************************************************************************
 *                                                                         *
 *   This file is part of the CrystalMem project,                          *
 *       http://code.google.com/p/crystalmem                               *
 *                                                                         *
 *   Copyright (C) 2008 by Alberto Scarpa <scarpa.alberto@gmail.com>       *
 *   Copyright (C) 2008 by Enrico Ros <enrico.ros@gmail.com>               *
 *                                                                         *
 *   This program is free software; you can redistribute it and/or modify  *
 *   it under the terms of the GNU General Public License as published by  *
 *   the Free Software Foundation; either version 2 of the License, or     *
 *   (at your option) any later version.                                   *
 *                                                                         *
 ***************************************************************************/

#ifndef __MemoryTree_h__
#define __MemoryTree_h__

#include "ProgramNode.h"
#include <QtCore/QList>
#include <QtCore/QFlags>
#include <QtCore/QRect>

class MemoryTree
{
    public:
        MemoryTree();
        ~MemoryTree();

        void traverse( /*,*/ qint32 size );

        // temp tree building *THIS IS BAD, ONLY FOR TESTING*
        typedef QList<quint64> Backtrace;
        ProgramNode * memoryAdded( const Backtrace & backTrace, quint32 size );
        void memoryRemoved( quint32 size, ProgramNode *node );

        // temp 4 Enrico
        void updateDynamics( double dT );
        enum RenderOption {
            ShowBranches        = 0x01,
            ShowAllocation      = 0x02,
            ShowTraversalCount  = 0x04,
            // ...
        };
        Q_DECLARE_FLAGS( RenderOpts, RenderOption );
        void renderGL( const QRect & rect, RenderOpts opts );

        void printTree();

    private:
        ProgramNode * m_root;
};

Q_DECLARE_OPERATORS_FOR_FLAGS( MemoryTree::RenderOpts );

#endif
